import { _decorator, Component, Node } from 'cc';
import { BaseItem } from '../BaseItem';
import { _item, _platform, _player, _tip } from '../../Main';
const { ccclass, property } = _decorator;

@ccclass('PropItem')
export abstract class PropItem extends BaseItem {

    storeAt: {} = _player.props

    buy(amount: number = 1, then?: () => void) {
        let coin: BaseItem = _item.items.Coin
        let cn: string = coin.getIdName()
        let num: number = _player.getDataNum(cn, coin.storeAt, 0)
        if (num < this.cost * amount) {
            _tip.tip('金币不足')
            return
        }
        _player.changeNumData(cn, coin.storeAt, -this.cost * amount, 'add', true, () => {
            this.get(amount, then)
        })
    }

    drop(amount: number = 1, then?: () => void) {
        let storeAt = this.storeAt
        let num: number = _player.getDataNum(this.getIdName(), storeAt, 0)
        if (num < amount) {
            _tip.tip(this.showName + ' 数量不足')
            return
        }
        _player.changeNumData(this.getIdName(), storeAt, -amount, 'add', true, () => {
            if (then) {
                then()
            }
        })
    }

    abstract use(): void

    abstract useable(): boolean

    videoThenUse(then?: () => void) {
        let pf = _platform.platform
        pf.showVideo(() => {
            this.use()
        })
    }
}


